package com.menu.web.controller.Information;

import com.menu.common.annotation.Log;
import com.menu.common.core.controller.BaseController;
import com.menu.common.core.domain.AjaxResult;
import com.menu.common.core.page.TableDataInfo;
import com.menu.common.enums.BusinessType;
import com.menu.common.utils.poi.ExcelUtil;
import com.menu.system.domain.MenuInformt;
import com.menu.system.service.IMenuInformtInfoService;
import com.menu.system.service.IMenuInformtService;
import com.menu.system.service.IreceptionRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 角色管理Controller
 *
 * @author ruoyi
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/system/informt")
public class MenuInformtController extends BaseController {
    @Autowired
    private IMenuInformtService menuInformtService;
    @Autowired
    private IMenuInformtInfoService menuInformtInfoService;
    @Autowired
    private IreceptionRoleService receptionRoleService;

    /**
     * 查询角色管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:informt:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuInformt menuInformt) {
        startPage();
        List<MenuInformt> list = menuInformtService.selectMenuInformtList(menuInformt);
        return getDataTable(list);

    }

    /**
     * 导出角色管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:informt:export')")
    @Log(title = "角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuInformt menuInformt) {
        List<MenuInformt> list = menuInformtService.selectMenuInformtList(menuInformt);
        ExcelUtil<MenuInformt> util = new ExcelUtil<MenuInformt>(MenuInformt.class);
        util.exportExcel(response, list, "角色管理数据");
    }

    /**
     * 获取角色管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:informt:query')")
    @GetMapping(value = "/{informtId}")
    public AjaxResult getInfo(@PathVariable("informtId") Long informtId) {

        AjaxResult ajax = AjaxResult.success();


        ajax.put(AjaxResult.DATA_TAG, menuInformtService.selectMenuInformtByInformtId(informtId));
        ajax.put("receptionRole", receptionRoleService.selectreceptionRoleList(null));
        ajax.put("roles", menuInformtInfoService.selectMenuProductInfoids(informtId));


        return ajax;

    }

    /**
     * 新增角色管理
     */
    @PreAuthorize("@ss.hasPermi('system:informt:add')")
    @Log(title = "角色管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuInformt menuInformt) {
        return toAjax(menuInformtService.insertMenuInformt(menuInformt));
    }

    /**
     * 修改角色管理
     */
    @PreAuthorize("@ss.hasPermi('system:informt:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuInformt menuInformt) {
        return toAjax(menuInformtService.updateMenuInformt(menuInformt));
    }

    /**
     * 删除角色管理
     */
    @PreAuthorize("@ss.hasPermi('system:informt:remove')")
    @Log(title = "角色管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{informtIds}")
    public AjaxResult remove(@PathVariable Long[] informtIds) {


        return toAjax(menuInformtService.deleteMenuInformtByInformtIds(informtIds));
    }
}
